package com.pansoft.openplanet.adapter;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * 首页广告弹窗PagerAdapter
 * Author by cimu
 * Date on 2019/1/7.
 */
public class DialogViewpagerAdapter extends PagerAdapter {
    private List<View> mList;
    public DialogViewpagerAdapter(List<View> list) {
        super();
        this.mList = list;
    }

    @Override
    public int getCount() {
        return this.mList.size();
    }
    /**初始化position界面*/
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ((ViewPager)container).addView(mList.get(position));
        return mList.get(position);
    }
    /**判断是否由对象生成界面*/
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    /**当切换的图片多于三张时会调用，用来销毁以前图片*/
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager)container).removeView(mList.get(position));
    }

}
